import { asyncRoutes, constantRoutes } from '@/router/index'
const state = {
  routes: []
}

const mutations = {
  setRoutes(state, route) {
    state.routes = [...constantRoutes, ...route]
  }
}

const actions = {
  /* 在导航守卫进行调用
       每次调用都进行根据--当前登录用户--获取到的 角色roles--进行页面的标识符对比
       该角色拥有的页面标识符--代表有这个页面的路由规则
    */
  filterRoutes(store, menus) {
    const res = asyncRoutes.filter(item => {
      return menus.includes(item.name)
    })
    store.commit('setRoutes', res)
    console.log('store/modules/permission-22-筛选后的路由', res)
    return res
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
